package com.imufe.chemicalenterprisedangerwarning.controller;

import com.imufe.chemicalenterprisedangerwarning.entity.query.CreateGroup;
import com.imufe.chemicalenterprisedangerwarning.entity.query.ProjectChemicalQuery;
import com.imufe.chemicalenterprisedangerwarning.entity.query.UpdateGroup;
import com.imufe.chemicalenterprisedangerwarning.entity.vo.ProjectChemicalDetailedVO;
import com.imufe.chemicalenterprisedangerwarning.service.ProjectChemicalService;
import com.imufe.chemicalenterprisedangerwarning.common.ResponseEntity;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 项目化学品表 前端控制器
 * </p>
 *
 * @author BaiBan
 * @since 2022-09-26
 */
@Api(tags = "项目化学品")
@RestController
@RequestMapping("/project-chemical")
public class ProjectChemicalController {

    @Autowired
    ProjectChemicalService service;

    @ApiOperation(value = "新增", notes = "新增一个项目化学品，返回新增的项目化学品信息")
    @PostMapping("/create")
    public ResponseEntity<ProjectChemicalDetailedVO> create(@RequestBody @Validated(CreateGroup.class) ProjectChemicalQuery query) {
        ProjectChemicalDetailedVO detailedVO = service.create(query);
        return ResponseEntity.success(detailedVO);
    }

    @ApiOperation(value = "删除", notes = "删除一个安监局")
    @DeleteMapping("/delete")
    public ResponseEntity<?> delete(@RequestBody Long id) {
        service.removeById(id);
        return ResponseEntity.success();
    }

    @ApiOperation(value = "修改", notes = "修改一个安监局，返回修改后的安监局信息")
    @PutMapping("/update")
    public ResponseEntity<ProjectChemicalDetailedVO> update(@RequestBody @Validated(UpdateGroup.class) ProjectChemicalQuery query) {
        ProjectChemicalDetailedVO detailedVO = service.update(query);
        return ResponseEntity.success(detailedVO);
    }
}
